package com.example.gzysmartcity.ui.fragment.hosp;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.example.gzysmartcity.R;
import com.example.gzysmartcity.databinding.FragmentDoctorBinding;
import com.example.gzysmartcity.repository.model.Reserve;
import com.example.gzysmartcity.ui.adapter.DoctorAdapter;
import com.example.gzysmartcity.ui.base.BaseFragment;
import com.example.gzysmartcity.viewmodel.DoctorViewModel;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class DoctorFragment extends BaseFragment<FragmentDoctorBinding> {

    private List<Reserve> reserves;

    @Override
    protected FragmentDoctorBinding viewBinding() {
        return FragmentDoctorBinding.inflate(getLayoutInflater(), baseBinding.getRoot(), true);
    }

    @Override
    public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        b.rvDoctor.setLayoutManager(new LinearLayoutManager(getContext()));
        DoctorViewModel doctorViewModel = new ViewModelProvider(this).get(DoctorViewModel.class);
        Bundle bundle = getArguments();
        if (bundle == null) return;
        int menzId = bundle.getInt("mzId");
        doctorViewModel.getMzId(menzId);
        doctorViewModel.getSCVisitData();
        doctorViewModel.getDoctorLiveData().observe(getViewLifecycleOwner(), state -> {
            switch (state) {
                case SUCCESS:
                    reserves = doctorViewModel.getReserve();
                    DoctorAdapter doctorAdapter = new DoctorAdapter(R.layout.rv_doctor);
                    doctorAdapter.setNewInstance(reserves);
                    b.rvDoctor.setAdapter(doctorAdapter);
                    break;
                case FAIL:
                    break;
            }
        });


    }

    @Override
    protected String setTitle() {
        return "选择医生";
    }

    @Override
    protected boolean showBack() {
        return true;
    }

    @Override
    protected Boolean showBottom() {
        return false;
    }
}
